package booksys.student;



import booksys.common.CurrentUser;
import booksys.common.Result;
import booksys.common.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author: ZhouLiang
 * @create: 2021-06-29 16:11
 **/
@WebServlet({
        "/student/studentList",

})
public class StudentAPI  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //接收客户端的参数,并将参数封装为java对象
        req.setCharacterEncoding("UTF-8");

        QueryDto queryDto = new QueryDto();
        queryDto.setSt_name("");
        queryDto.setSt_id("");
        queryDto.setSt_phone("");
      



        try {
            queryDto.setPageNum(Integer.parseInt(req.getParameter("pageNum")));
        } catch (Exception e) {}

        try {
            queryDto.setPageSize(Integer.parseInt(req.getParameter("pageSize")));
        } catch (Exception e) {}

        queryDto.setSt_name(req.getParameter("st_name"));
        queryDto.setSt_id(req.getParameter("st_id"));
        queryDto.setSt_phone(req.getParameter("st_phone"));
        
        //创建业务模型对象（服务对象/Service对象），通过业务对象执行业务方法
        CurrentUser currentUser = (CurrentUser) req.getSession().getAttribute(CurrentUser.SESSION_ATTR_NAME);
        StudentService studentService = new StudentService();
        Map<String,Object> page = studentService.getStudentList(queryDto);

        //通过视图生成json
        //Utils.outJson(response, studentList);
        Utils.outResult(resp, Result.success(page));
    }
}
